﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    >
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/XAMLMagicks;component/Styles/ButtonStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>
    <ControlTemplate TargetType="{x:Type ComboBox}" x:Key="FlatComboBoxTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="0" MinWidth="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" />
            </Grid.ColumnDefinitions>
            <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" 
                               PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" 
                               AllowsTransparency="True" Name="PART_Popup" Margin="1,1,1,1" Grid.ColumnSpan="2">
                <Border BorderThickness="1,1,1,1" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Name="DropDownBorder">
                    <ScrollViewer CanContentScroll="True">
                        <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" KeyboardNavigation.DirectionalNavigation="Contained" />
                    </ScrollViewer>
                </Border>
            </Popup>
            <ContentPresenter Content="{TemplateBinding ComboBox.SelectionBoxItem}" 
                                          ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}" 
                                          ContentStringFormat="{TemplateBinding ComboBox.SelectionBoxItemStringFormat}" 
                                          Margin="{TemplateBinding Control.Padding}" 
                                          HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" 
                                          VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" 
                                          SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" 
                                          IsHitTestVisible="False" />
            <ToggleButton Grid.Column="1" Style="{StaticResource FlatToggleButton}" 
                                      IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                      FontFamily="Webdings" Content="6" ClickMode="Press" Focusable="False" IsTabStop="False"                                      
                                      />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="ItemsControl.HasItems" Value="False">
                <Setter Property="FrameworkElement.Height" TargetName="DropDownBorder">
                    <Setter.Value>
                        <s:Double>95</s:Double>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="UIElement.IsEnabled" Value="False">
                <Setter Property="TextElement.Foreground">
                    <Setter.Value>
                        <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="ItemsControl.IsGrouping" Value="True">
                <Setter Property="ScrollViewer.CanContentScroll" Value="False" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    <Style TargetType="{x:Type ComboBox}" x:Key="FlatComboBox">
        <Setter Property="Template" Value="{StaticResource FlatComboBoxTemplate}" />
    </Style>
</ResourceDictionary>

